Questions
15 of 50
1What is a pseudo-class in CSS?
2How are pseudo-classes different from pseudo-elements?
3What is the syntax of a pseudo-class in CSS?
4Give some commonly used pseudo-classes.
5What does the :hover pseudo-class do?
6What’s the purpose of the :active pseudo-class?
7How does the :visited pseudo-class work for links?
8What is the :focus pseudo-class used for?
9What does the :checked pseudo-class do?
10How does the :disabled pseudo-class behave?
11What is the difference between :first-child and :first-of-type?
12How do :nth-child() and :nth-of-type() differ?
13How do you select every odd or even element using pseudo-classes?
14How can you style an element when it’s being hovered over along with its child?
15What does the :not() pseudo-class do?
16How can you use multiple pseudo-classes together?
17What is the difference between :link and :visited?
18What does the :target pseudo-class represent?
19How can you use :empty to detect empty elements?
20How does the :root pseudo-class differ from the html selector?
21What does the :valid and :invalid pseudo-class do?
22How can you use :required and :optional pseudo-classes in forms?
23What is the use of :in-range and :out-of-range?
24What does :read-only and :read-write do?
25How can you style an input field when it’s autofilled?
26How does the :focus-within pseudo-class work?
27What’s the difference between :focus and :focus-visible?
28What is the purpose of the :placeholder-shown pseudo-class?
29How can you style a checkbox when it is checked or unchecked?
30How can you style invalid form inputs without JavaScript?
31Can pseudo-classes be chained together? Give an example.
32What is the specificity of pseudo-classes compared to normal selectors?
33How can you use :not() effectively to exclude elements from styling?
34How does :has() pseudo-class work, and why is it powerful?
35Is :has() supported in all browsers?
36How does :is() differ from :where() in terms of specificity?
37How can you combine :is() or :where() with other selectors for cleaner code?
38What’s the difference between :nth-child() and :nth-last-child()?
39How can you style only the last element of a list using pseudo-classes?
40What does the :lang() pseudo-class do?
41How do you change a button’s color when hovered but not when disabled?
42How can you highlight the current section in a menu using :target?
43How can you style a form field differently when focused and valid?
44How do you style every third list item differently?
45How can you style alternate table rows without adding extra classes?
46How do you hide empty <p> tags using pseudo-classes?
47How can you style the parent when any child inside it is focused?
48How can you highlight a link only when it’s both focused and hovered?
49How can you style the first letter of only the first paragraph using pseudo-classes?
50How would you use :has() to select a <div> that contains an image?
15 / 50

What does the :not() pseudo-class do?

Understanding the :not() Pseudo-Class in CSS

The :not() pseudo-class in CSS allows you to select elements that do not match a particular selector. It is useful for excluding specific elements from a group while applying styles to others.

How :not() Works
  1. 1

    Use :not(selector) to exclude elements matching the given selector from being styled.

  2. 2

    It can be combined with other selectors to create more precise rules.

  3. 3

    :not() can take simple selectors like class, ID, or element type. In modern CSS, it can also accept complex selectors.

Example: Using :not()

In this example, the first and third list items are styled, while the second item with class 'exclude' is ignored. Similarly, the 'Submit' button is styled but the 'Cancel' button is excluded.

Best Practices
  1. 1

    Use :not() to simplify CSS and avoid adding extra classes for exclusions.

  2. 2

    Combine :not() with other pseudo-classes (like :hover) for more dynamic styling.

  3. 3

    Keep selectors simple for readability and performance.

  4. 4

    Test complex :not() rules across browsers to ensure consistency.

Difficulty: 3/10
Topics: CSS selectors, pseudo-classes, negation logic

Scenario Questions

0-2 years experience
  1. 1

    You're asked to style all paragraphs except the ones with a class of 'intro'. How would you write that CSS rule?

  2. 2

    If you write .button:not(.disabled) { color: blue; }, what happens to a button that has both class 'button' and 'disabled'?

  3. 3

    You have a list of items and want to apply a margin to all except the first one. How would you use :not() to do that?

2-5 years experience
  1. 1

    A designer says all cards should have a border except those inside a modal — but the border is still showing on modal cards. What could be wrong with the CSS rule using :not()?

  2. 2

    You're building a component library where a base button style applies to all buttons except those with data-variant='ghost'. Someone reports that the ghost variant still gets the base styles in some browsers. What might be the issue?

  3. 3

    A team member used :not(.hidden) to hide elements with display: none, but it's not working as expected. Why might that be, and what’s a better approach?

5-8 years experience
  1. 1

    You're optimizing a large-scale UI with 10k+ elements and using :not() extensively to avoid class bloat. How would you evaluate the performance impact, and when would you consider replacing it with explicit class-based styling?

  2. 2

    Your CSS architecture uses :not() to exclude components from global styles, but it's causing specificity wars in legacy code. How would you refactor this to improve maintainability without breaking existing styles?

  3. 3

    A component uses :not(:first-child) to add top margins, but it breaks when dynamically rendered content changes the DOM order. How would you design a more robust solution that doesn't rely on positional pseudo-classes?

8+ years experience
  1. 1

    You're leading a migration from a legacy CSS framework that uses inline classes for exclusion to a modern utility-first system. How would you architect a transition plan that minimizes regressions when replacing :not() patterns with explicit utility classes?

  2. 2

    Your company's design system uses :not() extensively for conditional styling across 50+ micro-frontends. How do you ensure consistency and avoid performance degradation as the number of selectors grows, and when would you enforce a ban on :not() in favor of semantic class naming?

  3. 3

    A cross-team component library relies on :not() to override global styles without requiring consumers to add exclusion classes. This creates hidden coupling. How would you redesign the API to make the contract explicit and reduce technical debt over time?

Follow-up Questions

  • Can you use :not() with multiple selectors inside it?
  • What happens if you pass an invalid selector to :not()?
  • How does :not() affect specificity compared to regular selectors?